﻿package net.wangit.view.element.component;

import net.wangit.Row;
import net.wangit.context.ActionContext;
import net.wangit.support.AbstractElementWriter;
import net.wangit.util.Checker;
import net.wangit.util.StringUtil;
import net.wangit.view.element.ElementComponent;
import net.wangit.view.element.util.ElementUtil;
import net.wangit.view.util.Html;

public class TipElementWriter extends AbstractElementWriter {

	public TipElementWriter() {
	}

	protected void writeText(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeTextWithValue(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		String title = ElementUtil.resolveTitle(ac, ec, row);
		title = StringUtil.replace(title, "'", "'");
		html.append("<img onclick=\"_showTip('");
		html.append(title).append("')\"");
		Html.setCss(html, ec.getCss());
		Html.setAttribute(html, ElementUtil.resolveCustom(ac, ec, row));
		Html.setWidth(html, ec.getWidth());
		Html.setHeight(html, ec.getHeight());
		String link = ElementUtil.resolveLink(ac, ec, row);
		if (Checker.isEmpty(link))
			link = "/common/images/help/help.png";
		Html.setSrc(html, link);
		html.append("/>");
	}

	protected void writeReadOnlyControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeDisabledControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeHidden(ActionContext actioncontext,
			StringBuffer stringbuffer, ElementComponent elementcomponent,
			Row row1) {
	}
}
